package com.ziyucoding.springboot.labs.lab2.kafkademo.consumer;

import com.ziyucoding.springboot.labs.lab2.kafkademo.message.DemoMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 消费者示例1
 *
 * @author ziyucoding
 * @date 2022-10-11
 **/
@Component
public class Demo1Biz1Consumer {

    private Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 每个消费者分组职责单一，只消费一个 Topic。
     * 按业务 biz 分开。
     *
     * @param messages
     * @return void
     **/
    @KafkaListener(topics = DemoMessage.TOPIC,
            groupId = "demo1-biz1-consumer-group-" + DemoMessage.TOPIC)
    public void onMessage(List<DemoMessage> messages) {
        logger.info("[onMessage][线程编号:{} 消息数量：{}]", Thread.currentThread().getId(), messages.size());
    }
}
